//
//  CXHTopOnNativeObject.m
//  CXHAdSDK-TopOn
//
//  Created by 陈坤 on 2025/10/18.
//

#import "CXHTopOnNativeObject.h"
#import <CXHAdSDK-Kit/CXHUtilsKit.h>

@interface CXHTopOnNativeObject ()

@property (nonatomic, strong) ATNativeAdRenderConfig *configuration;

@end

@implementation CXHTopOnNativeObject

#pragma mark - 推荐实现，释放资源
- (void)dealloc {
//    [[self getMSFeedVideoView] unregisterDataObject];
//    [self.feedAdMetaad unAttachAd];
}

#pragma mark - 必须实现，获取配置并设置给自定义广告平台 SDK
- (void)setNativeADConfiguration:(ATNativeAdRenderConfig *)configuration {
    self.configuration = configuration;
//    [self getMSFeedVideoView].presentVc = configuration.rootViewController;
}

#pragma mark - 必须实现，根据渲染类型注册容器
- (void)registerClickableViews:(NSArray<UIView *> *)clickableViews withContainer:(UIView *)container registerArgument:(ATNativeRegisterArgument *)registerArgument{
    if (self.nativeAdRenderType == ATNativeAdRenderExpress) {
        UIView<CXHAdapterNativeExpressAdViewDelegate> *nativeExpressAdView = (UIView<CXHAdapterNativeExpressAdViewDelegate> *)self.templateView;
        if (self.configuration.rootViewController) {
            [nativeExpressAdView cxh_setRootViewController:self.configuration.rootViewController];
        }
        [nativeExpressAdView render];
        return;
    }
//    NSMutableArray<UIView *> *views = [NSMutableArray array];
//    if (!kCXHArrayIsEmpty(clickableViews)) {
//        [views addObjectsFromArray:[clickableViews copy]];
//    }
//    [views addObject:self.nativeAdView];
//    self.nativeAdView.backgroundColor = [UIColor greenColor];
    self.nativeAdView.frame = container.bounds;
    if (self.configuration.rootViewController) {
        [self.nativeAdView cxh_setRootViewController:self.configuration.rootViewController];
    }
    [self.nativeAdView cxh_registViews:clickableViews];
    [container insertSubview:self.nativeAdView atIndex:0];
}

@end
